<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="批准文号">
              <a-input placeholder="请输入批准文号" v-model="queryParam.yid"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="药品名称">
              <a-input placeholder="请输入药品名称" @blur="ynamefun" v-model="queryParams.yname"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="12" :sm="16">
              <a-form-item label="库存数量">
                <a-input-number placeholder="请输入最小值" @blur="stocksfun" class="query-group-cust" v-model="queryParam.stocks_begin"></a-input-number>
                <span class="query-group-split-cust"></span>
                <a-input-number placeholder="请输入最大值" @blur="stocksfun" class="query-group-cust" v-model="queryParam.stocks_end"></a-input-number>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="16">
              <a-form-item label="参考进价">
                <a-input-number placeholder="请输入最小值" @blur="yppricefun" class="query-group-cust" v-model="queryParam.ypprice_begin"></a-input-number>
                <span class="query-group-split-cust"></span>
                <a-input-number placeholder="请输入最大值" @blur="yppricefun" class="query-group-cust" v-model="queryParam.ypprice_end"></a-input-number>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="16">
              <a-form-item label="有效期">
                <j-date placeholder="请选择开始日期" @change="musetimefun" class="query-group-cust" v-model="queryParam.musetime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" @change="musetimefun" class="query-group-cust" v-model="queryParam.musetime_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="16">
              <a-form-item label="生产日期">
                <j-date placeholder="请选择开始日期" @change="jyscrqfun" class="query-group-cust" v-model="queryParam.jyscrq_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date placeholder="请选择结束日期" @change="jyscrqfun" class="query-group-cust" v-model="queryParam.jyscrq_end"></j-date>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="16">
              <a-form-item label="供应商名称">
                <a-input placeholder="请输入供应商名称" @blur="gysnamefun" v-model="queryParams.gysname"></a-input>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('药品信息表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{fixed:true,selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <MedicineBuyerModal ref="modalForm" @ok="modalFormOk"></MedicineBuyerModal>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MedicineBuyerModal from './modules/MedicineBuyerModal'
  import JDate from '@/components/jeecg/JDate.vue'

  export default {
    name: "MedicineInfoList",
    mixins:[JeecgListMixin],
    components: {
      JDate,
        MedicineBuyerModal
    },
    data () {
      return {
        description: '药品进货表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
            {
                title:'创建人',
                align:"center",
                dataIndex: 'createBy'
            },
            {
                title:'创建日期',
                align:"center",
                dataIndex: 'createTime'
            },
          {
            title:'批准文号',
            align:"center",
            dataIndex: 'yid'
          },
          {
            title:'药品名称',
            align:"center",
            dataIndex: 'yname'
          },
          {
            title:'进货数量',
            align:"center",
            dataIndex: 'stocks'
          },
          {
            title:'参考进价',
            align:"center",
            dataIndex: 'ypprice'
          },
            {
                title:'供应商',
                align:"center",
                dataIndex: 'gysname'
            },
            {
                title:'生产日期',
                align:"center",
                dataIndex: 'jyscrq'
            },
            {
                title:'有效日期',
                align:"center",
                dataIndex: 'musetime'
            },
            {
                title:'备注',
                align:"center",
                dataIndex: 'jyremarks'
            },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/medicine/medicineBuyer/list",
          delete: "/medicine/medicineBuyer/delete",
          deleteBatch: "/medicine/medicineBuyer/deleteBatch",
          exportXlsUrl: "/medicine/medicineBuyer/exportXls",
          importExcelUrl: "medicine/medicineBuyer/importExcel",
        },
        dictOptions:{
        },
          data: [],
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
      created(){
      },
    methods: {
      initDictConfig(){
      },
        ynamefun(){
            this.queryParam.yname='*'+this.queryParams.yname+'*';
        },
        gysnamefun(){
            this.queryParam.gysname='*'+this.queryParams.gysname+'*';
        },
        yppricefun(){
            if(this.queryParam.ypprice_begin!=''&&this.queryParam.ypprice_end!=''){
                if(this.queryParam.ypprice_begin>this.queryParam.ypprice_end){
                    this.$message.error('进价最小值必须小于最大值');
                    this.queryParam.ypprice_begin='';
                    this.queryParam.ypprice_end='';
                }
            }
        },
        stocksfun(){
            if(this.queryParam.stocks_begin!=''&&this.queryParam.stocks_end!=''){
                if(this.queryParam.stocks_begin>this.queryParam.stocks_end){
                    this.$message.error('售价最小值必须小于最大值');
                    this.queryParam.stocks_begin='';
                    this.queryParam.stocks_end='';
                }
            }
        },musetimefun(){
            if(this.queryParam.musetime_begin!=''&&this.queryParam.musetime_end!=''){
                if(this.queryParam.musetime_begin>this.queryParam.musetime_end){
                    this.$message.error('开始时间必须小于结束时间');
                    this.queryParam.musetime_begin='';
                    this.queryParam.musetime_end='';
                }
            }
        },
        jyscrqfun(){
            if(this.queryParam.jyscrq_begin!=''&&this.queryParam.jyscrq_end!=''){
                if(this.queryParam.jyscrq_begin>this.queryParam.jyscrq_end){
                    this.$message.error('开始时间必须小于结束时间');
                    this.queryParam.jyscrq_begin='';
                    this.queryParam.jyscrq_end='';
                }
            }
        }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>